package com.ruoyi.common.core.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 部门表 sys_dept
 *
 * @author ruoyi
 */
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
@ToString
@ApiModel(value = "部门")
@Entity
@Table(name = "sys_dept")
@TableName(value = "sys_dept")
public class SysDept extends BaseEntity {
    
    private static final long serialVersionUID = 5218500183816922751L;
    /**
     * 部门ID
     */

    @ApiModelProperty(value = "部门id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "dept_id")
    @TableId(value = "dept_id")
    private Long deptId;

    /**
     * 父部门ID
     */

    @ApiModelProperty(value = "父部门id")
    @Column(name = "parent_id")
    @TableField(value = "parent_id")
    private Long parentId;

    /**
     * 祖级列表
     */
    @ApiModelProperty(value = "祖级列表")
    @Column(name = "ancestors", length = 50)
    @TableField(value = "ancestors")
    private String ancestors;

    /**
     * 部门名称
     */
    @ApiModelProperty(value = "部门名称")
    @NotBlank(message = "部门名称不能为空")
    @Size(max = 30, message = "部门名称长度不能超过30个字符")
    @Column(name = "dept_name", length = 30)
    @TableField(value = "dept_name")
    private String deptName;

    /**
     * 显示顺序
     */

    @ApiModelProperty(value = "显示顺序")
    @NotNull(message = "显示顺序不能为空")
    @Column(name = "order_num")
    @TableField(value = "order_num")
    private Integer orderNum;

    /**
     * 负责人
     */

    @ApiModelProperty(value = "负责人")
    @Column(name = "leader", length = 20)
    @TableField(value = "leader")
    private String leader;

    /**
     * 联系电话
     */

    @ApiModelProperty(value = "联系电话")
    @Size(max = 11, message = "联系电话长度不能超过11个字符")
    @Column(name = "phone", length = 11)
    @TableField(value = "phone")
    private String phone;

    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    @Email(message = "邮箱格式不正确")
    @Size(max = 50, message = "邮箱长度不能超过50个字符")
    @Column(name = "email", length = 50)
    @TableField(value = "email")
    private String email;

    /**
     * 部门状态:0正常,1停用
     */

    @ApiModelProperty(value = "部门状态:0正常,1停用")
    @Column(name = "status", length = 1)
    @TableField(value = "status")
    private String status;

    /**
     * 删除标志（0代表存在 2代表删除）
     */

    @ApiModelProperty(value = "删除标志（0代表存在 2代表删除）")
    @Column(name = "del_flag", length = 1, columnDefinition = "  VARCHAR(1) DEFAULT '0'  ")
    @TableField(value = "del_flag")
    private String delFlag;

    /**
     * 父部门名称
     */
    @ApiModelProperty(value = "父部门名称")
    @Transient
    @TableField(exist = false)
    private String parentName;

    /**
     * 子部门
     */
    @ApiModelProperty(value = "子部门")
    @Transient
    @TableField(exist = false)
    private List<SysDept> children = new ArrayList<>();

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        SysDept sysDept = (SysDept) o;
        return getDeptId() != null && Objects.equals(getDeptId(), sysDept.getDeptId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
